package com.ktjy.crm.web;

import com.ktjy.crm.entity.User;
import com.ktjy.crm.service.SysUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.plaf.ListUI;
import java.util.List;

@RestController
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/user")
    public String hello(@Param("id") Long id) {
        User user = sysUserService.get(id);
        return "名称："+ user.getRealName();
    }

    @RequestMapping("/add")
    public String add(@Param("user") User user) {
//        User user = new User();
//        user.setRealName("管理员");
//        user.setPassword("123456");
//        user.setSex(1);
//        user.setRoleId(1);

        int result = sysUserService.insert(user);
        return "添加成功："+ result;
    }

    @RequestMapping("/delete")
    public String delete(@Param("id") Long id) {
        int result = sysUserService.delete(id);
        return "删除成功："+ result;
    }

    @RequestMapping("/update")
    public String update(@Param("user") User user) {
//        user.setId(17L);
//        user.setRealName("管理员");
//        user.setPassword("12345");
//        user.setSex(0);
//        user.setRoleId(1);

        int result = sysUserService.update(user);
        return "修改成功："+ result;
    }

    @RequestMapping("/findAll")
    public List<User> findAll() {
        List<User> list = sysUserService.findAll();
        return list;
    }
}
